/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NV_QuanLyThongTin.java
 *
 * Created on 14-05-2012, 22:36:28
 */
package GUI;

import DAO.NhanVienDAO;
import POJO.NhanVienPoJo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.sql.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author tran quoc thinh
 */
public class NV_QuanLyThongTin extends javax.swing.JInternalFrame {

    /** Creates new form NV_QuanLyThongTin */
    public NV_QuanLyThongTin() {
        initComponents();
        jtxtTenDangNhap.setText(nv.getUserName());
        jtxtDienThoai.setText(nv.getDienThoai());
        jtxtHoTen.setText(nv.getTenNV());
        jtxtNgaySinh.setText(nv.getNgaySinh().toString());
        jtxtDiaChi.setText(nv.getDiaChi());
    }
    
    public NV_QuanLyThongTin(NhanVienPoJo nv1)
    {
        nv = new NhanVienPoJo(nv1);
        initComponents();
        jtxtTenDangNhap.setText(nv.getUserName());
        jtxtDienThoai.setText(nv.getDienThoai());
        jtxtHoTen.setText(nv.getTenNV());
        jtxtNgaySinh.setText(nv.getNgaySinh().toString());
        jtxtDiaChi.setText(nv.getDiaChi());
    }
    public NhanVienPoJo nv = new NhanVienPoJo();

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtxtTenDangNhap = new javax.swing.JTextField();
        jtxtHoTen = new javax.swing.JTextField();
        jtxtNgaySinh = new javax.swing.JTextField();
        jtxtDiaChi = new javax.swing.JTextField();
        jtxtDienThoai = new javax.swing.JTextField();
        jbtnCapNhat = new javax.swing.JButton();
        jbtnHuyCapNhat = new javax.swing.JButton();
        jtxtMatKhau = new javax.swing.JPasswordField();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("Tên Đăng Nhập:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Mật Khẩu:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Họ Tên:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Ngày Sinh:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Địa Chỉ:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Điện Thoại:");

        jtxtTenDangNhap.setEditable(false);
        jtxtTenDangNhap.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jtxtHoTen.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jtxtNgaySinh.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jtxtNgaySinh.setText("yyyy-mm-dd");

        jtxtDiaChi.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jtxtDienThoai.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jbtnCapNhat.setText("Cập Nhật");
        jbtnCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCapNhatActionPerformed(evt);
            }
        });

        jbtnHuyCapNhat.setText("Hủy Cập Nhật");
        jbtnHuyCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnHuyCapNhatActionPerformed(evt);
            }
        });

        jtxtMatKhau.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1))
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6))
                                .addGap(18, 18, 18)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                    .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jtxtTenDangNhap, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jtxtMatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(241, 241, 241)
                        .addComponent(jbtnCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnHuyCapNhat)))
                .addGap(148, 148, 148))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jtxtTenDangNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtMatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)))
                    .addComponent(jLabel5))
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnHuyCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(91, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbtnCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCapNhatActionPerformed
// TODO add your handling code here:
    nv.setDiaChi(jtxtDiaChi.getText());
    nv.setDienThoai(jtxtDienThoai.getText());    
    nv.setPassword(jtxtMatKhau.getText());
    nv.setTenNV(jtxtHoTen.getText());
    Date ngaysinh = Date.valueOf(jtxtNgaySinh.getText());
    nv.setNgaySinh(ngaysinh);
//    Date ngaysinh = new Date();
//    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");   
//    try {
//        ngaysinh= sdf.parse(this.jtxtNgaySinh.getText().trim().toString());
//    } catch (ParseException ex) {
//        Logger.getLogger(Ad_NhanVienInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
//    }   
   
    
    nv.setUserName(jtxtTenDangNhap.getText());
    try
    {
        NhanVienDAO.CapNhatNhanVien(nv);
        JOptionPane.showMessageDialog(this, "Cập Nhật Thành Công!");
    }catch(Exception ex)
    {
        JOptionPane.showMessageDialog(this, "Cập Nhật Thất Bại!");
    }
}//GEN-LAST:event_jbtnCapNhatActionPerformed

private void jbtnHuyCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHuyCapNhatActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_jbtnHuyCapNhatActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JButton jbtnCapNhat;
    private javax.swing.JButton jbtnHuyCapNhat;
    private javax.swing.JTextField jtxtDiaChi;
    private javax.swing.JTextField jtxtDienThoai;
    private javax.swing.JTextField jtxtHoTen;
    private javax.swing.JPasswordField jtxtMatKhau;
    private javax.swing.JTextField jtxtNgaySinh;
    private javax.swing.JTextField jtxtTenDangNhap;
    // End of variables declaration//GEN-END:variables
}
